package com.example.nbshopping.fuzzysearch;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.example.nbshopping.R;
import com.example.nbshopping.com.example.nbshopping.login_reg.UserBean;
import com.example.nbshopping.goods.GoodsBean;
import com.example.nbshopping.goods.LikeAdapter;
import com.example.nbshopping.goods.TypeBean;
import com.example.nbshopping.utils.BaseActivity;
import com.example.nbshopping.utils.URLUtils;
import com.google.gson.Gson;

import org.xutils.http.RequestParams;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

public class FuzzySearchLeaderActivity extends BaseActivity {
    EditText et_search_input;
    Button btn_history_input;
    ImageView iv_search;
    List<TypeBean.DataBean> data;
    ListView lv_guess_u_like;
    TypeBean.DataBean dataBean;
    private FuzzySearchAdapter adapter;
    private UserBean.DataBean userInfo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fuzzy_search_leader);//绑定布局
        initView();//初始化视图
        setListener();//设置监听
        getNetwork(URLUtils.guessYouLike_url);//启动网络
    }
    private void setListener() {
        iv_search.setOnClickListener(clickListener);
        et_search_input.setOnClickListener(clickListener);
    }
    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.search_iv:
                    String et_search = et_search_input.getText().toString();
                    RequestParams params1 = new RequestParams(URLUtils.queryCommodityByName_url);
                    params1.addParameter("name",et_search);
                    x.http().get(params1, FuzzySearchLeaderActivity.this);
                    break;
            }
        }
    };

    @Override
    public void onSuccess(String result) {

        super.onSuccess(result);
        TypeBean typeBean = new Gson().fromJson(result, TypeBean.class);
        List<TypeBean.DataBean> list = typeBean.getData();

        data = new ArrayList<>();
        data.addAll(list);
        adapter.notifyDataSetChanged();

        //适配器，数据类型不一样自然也不一样的适配器
        adapter = new FuzzySearchAdapter(this,data);
        lv_guess_u_like.setAdapter(adapter);
    }

    private void initView() {
        et_search_input = findViewById(R.id.search_et);
        lv_guess_u_like = findViewById(R.id.lv_search_guess_u_like);
        iv_search = findViewById(R.id.search_iv);
    }
    /*主搜索页面
    * 1.商品模糊查询输入条，求类型get，请求地址/biz/queryCommodityInfo
    * EditText获得文本，请求参数(必须)String name，是模糊查询的字段。
    * 返回参数：(int)code，(String)message，(List<E>)data*/
}